package database

import (
	"fmt"
	"os"

	"gorm.io/driver/postgres"
	"gorm.io/gorm"
)

type Database struct {
	DB *gorm.DB
}

var (
	DB_HOST     = os.Getenv("DB_HOST")
	DB_PORT     = os.Getenv("DB_PORT")
	DB_DATABASE = os.Getenv("DB_DATABASE")
	DB_USERNAME = os.Getenv("DB_USERNAME")
	DB_PASSWORD = os.Getenv("DB_PASSWORD")
)

func New() (*Database, error) {
	db, err := gorm.Open(postgres.Open(
		fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=%v sslmode=disable", DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT)),
		&gorm.Config{},
	)
	if err != nil {
		return nil, err
	}

	return &Database{
		DB: db,
	}, nil

}
